<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="zh-cn">
    <head>
        <!-- Bootstrap -->
        <include file="Include/css" />
        <title>中经汇通-首页</title>
        <link href="__STATICS__/css/admin/index.css" rel="stylesheet">
        <link href="__STATICS__/css/sweet-alert.css" rel="stylesheet">
        <script type="text/javascript" src="__STATICS__/js/sweet-alert.min.js"></script>

    </head>
    <body>
        <include file="Include/nav_top" />
        <div class="container clearfix" id="left_menu_wraper" >
            <include  file="Include/menu_left" />
            <div id="right-content">
                <div id="right-content-inner">
                    <ul class="breadcrumb">
                        <span>您的位置：</span>
                        <li><a href="{:U('CNEPAdmin/Index/index')}">首页</a> </li>
                        <li class="">分类管理</li>
                        <li class="active">分类列表</li>
                    </ul>


                    <div id="message_wraper" style="display: none;"   class="alert alert-info  alert-dismissible" role="alert">

                        关闭按钮
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        内容

                        <strong>温馨提示：</strong> <span id="message" >{$lastsql}</span>
                    </div>
                    <p>
                        <button id="add_look" class="btn btn-orange" type="button" >
                            添加分类
                        </button>
                    </p>

                    <div role="tabpanel">

                        <div class="row clearfix margin10 form-horizontal">
                            <form  name="query" method="POST" >
                                <span class="pull-left ml30 form_bar">查询：</span>
                                <div class="col-md-2">
                                    <input type="text" name="name" value="{$Think.post.name}" placeholder="名称" class="pull-left ml10 form-control" />
                                </div>
                                <button type="submit" class="pull-left btn btn-default ml20">
                                    搜索
                                </button>
                            </form>

                        </div>

                        <table class="table table-striped table_qrcode  table-hover">
                            <!--<caption>标题</caption>-->
                            <thead>
                                <tr class="border">
                                    <th>编号</th>
									<th>类别</th>
                                    <th>分类名称</th>
                                    <th>父级</th>
                                    <th>次序</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <volist name="list" id="vo">
                                    <tr class="qr_tar">
                                        <td>
                                            {$vo.categoryID}
                                        </td>
										<td>
                                            <switch name='vo.type'>
	                                                	<case value='1'>活动专区</case>
	                                                	<case value='2'>银行专区</case>
	                                                	<case value='3'>电信运营商</case>
                                            </switch>
                                        </td>
                                        <td>
                                                {$vo.name}
                                        </td>
                                     
                                        <td>{$vo.parent_name} </td>
                                        <td>{$vo.sort} </td>
                                        <td data-id="{$vo.categoryID}"><a href="javascript:void(0)" class="edit_look" onclick="edit({$vo.categoryID},'{$vo.name}',{$vo.parentID},{$vo.sort},{$vo.type})" >编辑</a> 
                                            /
                                            <a href="javascript:void(0)" class="tar_delete"  >删除</a> 
                                        </td>
                                    </tr>
									<input type="hidden" id="imghidden{$vo.categoryID}" value="{$imgDomain}{$vo.img}">
                                </volist>
                            </tbody>
                        </table>

                        <div class="clearfix s_page pull-right">
                            {$page}
                        </div>

                    </div>

                </div>

            </div>
        </div>

        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel"> </h4>
                    </div>
                    <div class="modal-body">
                        <div id="message_w_alert" style="display: none;" data-id="alert-info"  class="alert alert-info  alert-dismissible" role="alert">

                            <!--关闭按钮-->
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            <!--内容-->

                            <strong>提示：</strong> <span id="message_alert" ></span>
                        </div>
                        
                            <div class="row clearfix">
							
							
							
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        分类名称：
                                    </div>
                                    <div class="col-md-6">
                                        <input id="name" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-1 text_warning text_left form_bar">
                                        *
                                    </div>
                                </div>
                                
								<div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                               类别：
                                    </div>
                                    <div class="col-md-7">
                                        <label class="radio-inline">
                                            <input type="radio" name="type" id="inlineRadio1" value="1" checked> 活动专区
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="type" id="inlineRadio2" value="2"> 银行专区
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="type" id="inlineRadio2" value="3"> 电信运营商
                                        </label>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    *
                                    </div>
                                </div>
								
								<div class="col-md-12 margin10">
                            <div class="col-md-2 text_right form_bar">
                                    父级：
                            </div>
                            <div class="col-md-6">
								<input id="parentID" type="text" class="form-control" placeholder="填写父级分类ID"/>
                            </div>
                            <div class="col-md-1 text_warning text_left form_bar">
                                    *
                            </div>
                    </div>
								
                              <div class="col-md-12 margin10" id="typevalue">
                                    <div class="col-md-2 text_right form_bar">
                                        排序
                                    </div>
                                    <div class="col-md-7">
                                        <input id="sort" type="text" class="form-control" placeholder="输入排序号"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        *号码越小排越前(可空,默认按时间排序)
                                    </div>
                                </div>
								
							<div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        分类图标：
                                    </div>
                                    <div class="col-md-7">
                                        <div class="upload_wraper dash clearfix" style="width:200px;height:200px;">
                                            <img src="__STATICS__/images/upload_comn.png" class=" col-xs-12" id="pic" alt=""/>
                                            <input type="file" class="input_file" id="fileupload" name="file" value="" data-url="" multiple=""/>
                                        </div>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        *
                                    </div>
                                </div>
								
                                <input id="categoryID" type="hidden" />
                                
                            </div>
                            

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="save" >保存</button>
                    </div>
                </div>
            </div>
        </div>

        <include file="Include/script" />
		<script src="__STATICS__/js/jquery.ui.widget.js"></script>
        <script src="__STATICS__/js/jquery.iframe-transport.js"></script>
        <script src="__STATICS__/js/jquery.fileupload.js"></script>
        <script src="__STATICS__/js/jquery-form.js"></script>
        
        <script src="__STATICS__/js/admin/hzAjax.js" type="text/javascript"></script>
        <script type="text/javascript" src="__STATICS__/js/admin/shopMsg.js"></script>
        <script>
            var reload = false;
            var headImgUrl = "{:U('CNEPAdmin/Upload/uploadImg',array('pathType'=>7))}";
            /*菜单展开及高亮*/
            $(function () {
                $('.region').addClass('open');
                $('#category').addClass('active');

                $('#myModal').on('hidden.bs.modal', function (e) {
                    if(reload) {
                        window.location.reload();
                    }
                 });

                $("#add_look").on("click", function () {
                    $("#categoryID").val("");
                    $("#name").val("");
                    $("#parentID").val("");
					$("#sort").val("");
					$("#pic").attr('src',"__STATICS__/images/upload_comn.png");
					$('[name="type"][value="1"]').prop('checked','checked').trigger('change');
                    $("#myModalLabel").html("添加地区");
                    $('#myModal').modal(); // 跳出弹窗
                });
                $(".edit_look").on("click", function () {
                            $("#myModalLabel").html("编辑分类");
                            $('#myModal').modal(); // 跳出弹窗
                });

                $("#save").on("click", function () {
                    if (checkValue()) {
                        var name = $.trim($("#name").val());
                        var parentID = parseInt($.trim($("#parentID").val()));
						var sort = parseInt($.trim($("#sort").val()));
                        var categoryID = parseInt($.trim($("#categoryID").val()));
                        var type = $('input[name="type"]:checked').val();
						var path = $('#pic').attr('src');
                        var ajaxData = {};
                        if(categoryID > 0) {
                            ajaxData.categoryID = categoryID;
                        }
                        ajaxData.name = name;
                        ajaxData.parentID = parentID;
						ajaxData.sort = sort;
						ajaxData.type = type;
						if(path!='/statics/images/upload_comn.png'){
                        	ajaxData.img = path;
                        }
                        ajax_go(ajaxData ,"{:U('CNEPAdmin/Category/saveCategory')}",true);
                    }
                });
                
                $(".tar_delete").on("click", function () {
                    var self = $(this);
                    swal({   title: "您确定吗?",
                                text: "您将删除此账号！",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "是的，删除",
                                cancelButtonText: "放弃",
                                closeOnConfirm: false
                            },
                            function (isConfirm) {
                                if (isConfirm) {
                                    var ajaxData = {};
                                    ajaxData.categoryID = self.closest('td').attr('data-id');
                                    ajax_go(ajaxData ,"{:U('CNEPAdmin/Category/deleteCategory')}",true);
                                }

                            });


                });

            });
            
            function edit(id,name,parentID,sort,type) {
				var img = $("#imghidden"+id).val();
                $("#categoryID").val(id);
                $("#name").val(name);
				$("#parentID").val(parentID);
                $("#sort").val(sort);
				$("#pic").attr('src',img);
				$(':radio[name="type"][value="'+type+'"]').prop("checked",true);
            }
            
            function checkValue() {
                var rt = true;
                var msg = '';

                var name = $.trim($("#name").val());
                var parentID = parseInt($.trim($("#parentID").val()));
				var sort = parseInt($.trim($("#sort").val()));
                var categoryID = parseInt($.trim($("#categoryID").val()));

                if (name.length == 0) {
                    rt = false;
                    msg = "分类名称不能为空";
                    $("#name").focus();
                }  else if(isNaN(parseInt(sort))) {
                    rt = false;
                    msg = "请正确输入排序";
                    $("#sort").focus();
                }
                
                if (!rt) {
                    swal(msg,'','warning');
                } else {
                    swal('正在保存...','','warning');
                }
                return rt;
            }
			
			upload_img(headImgUrl,'fileupload','pic','imgPath','thumb');
            
        </script>
    </body>
</html>